package com.material.web.controller.supplier;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.material.common.utils.SecurityUtils;
import com.material.supplier.params.SupplierCarQuery;
import com.material.supplier.vo.SupplierCarVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.material.common.annotation.Log;
import com.material.common.core.controller.BaseController;
import com.material.common.core.domain.AjaxResult;
import com.material.common.enums.BusinessType;
import com.material.supplier.domain.SupplierCar;
import com.material.supplier.service.ISupplierCarService;
import com.material.common.utils.poi.ExcelUtil;
import com.material.common.core.page.TableDataInfo;

/**
 * 车辆管理Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/supplier/car")
public class SupplierCarController extends BaseController
{
    @Autowired
    private ISupplierCarService supplierCarService;

    /**
     * 查询车辆管理列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplierCarQuery supplierCar)
    {
        Long bizId = getBizId();
        boolean admin = SecurityUtils.isAdmin(getUserId());
        if(!admin){
            supplierCar.setFactoryId(bizId);
        }
        startPage();
        List<SupplierCarVo> list = supplierCarService.selectSupplierCarPageList(supplierCar);
        return getDataTable(list);
    }

    /**
     * 导出车辆管理列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:car:export')")
    @Log(title = "车辆管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierCar supplierCar)
    {
        List<SupplierCar> list = supplierCarService.selectSupplierCarList(supplierCar);
        ExcelUtil<SupplierCar> util = new ExcelUtil<SupplierCar>(SupplierCar.class);
        util.exportExcel(response, list, "车辆管理数据");
    }

    /**
     * 获取车辆管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('supplier:car:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(supplierCarService.selectSupplierCarById(id));
    }

    /**
     * 新增车辆管理
     */
    @PreAuthorize("@ss.hasPermi('supplier:car:add')")
    @Log(title = "车辆管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplierCar supplierCar)
    {
        return toAjax(supplierCarService.insertSupplierCar(supplierCar));
    }

    /**
     * 修改车辆管理
     */
    @PreAuthorize("@ss.hasPermi('supplier:car:edit')")
    @Log(title = "车辆管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierCar supplierCar)
    {
        return toAjax(supplierCarService.updateSupplierCar(supplierCar));
    }

    /**
     * 删除车辆管理
     */
    @PreAuthorize("@ss.hasPermi('supplier:car:remove')")
    @Log(title = "车辆管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(supplierCarService.deleteSupplierCarByIds(ids));
    }
}
